var roleBuilderio = {

     /** @param {Creep} creep **/
	 run: function(creep) {
        creep.say(creep.memory.building);
        if(creep.store[RESOURCE_ENERGY] == 0){
            creep.memory.building = true;
        }
        else{
            creep.memory.building = false;
        }

        if(creep.memory.building == true){
            creep.say(creep.memory.building);
            var targetsgo = creep.room.find(FIND_STRUCTURES, {
                filter: (structure) => {
                    return structure.structureType == STRUCTURE_CONTAINER && structure.store.getUsedCapacity() > 0;
                }
            });
            if(targetsgo.length > 0) {
                if(creep.withdraw(targetsgo[1], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
                    creep.moveTo(targetsgo[1]);
                    creep.say('建来');
                }
            }   
        }
        else{
            var targets = creep.room.find(FIND_CONSTRUCTION_SITES);
            if(targets.length) {
                if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
                    creep.moveTo(targets[0]);
                    creep.say('建去');
                }
            } 
        }
	}
};

module.exports = roleBuilderio;